package com.yvon.service.demo.netty.server;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

import java.nio.charset.Charset;
import java.util.Date;

/**
 * @author yvon
 * @since 2023-06-02
 */
public class MyServerHandler extends ChannelInboundHandlerAdapter {

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        // 接受msg消息
        ByteBuf buf = (ByteBuf) msg;
        byte[] mgsByte = new byte[buf.readableBytes()];
        buf.readBytes(mgsByte);
        System.out.println(new Date() + "接收到消息：");
        System.out.println(new String(mgsByte, Charset.forName("GBK")));
    }
}
